package com.xiaotao.controller;

<<<<<<< HEAD
import com.xiaotao.dto.TeamApplyDTO;
import com.xiaotao.dto.TeamDetailDTO;
import com.xiaotao.entity.TeamMember;
import com.xiaotao.service.TeamService;
=======
import com.xiaotao.entity.TeamMember;
import com.xiaotao.service.TeamService;
import lombok.extern.slf4j.Slf4j;
>>>>>>> 3e34457f1997fafc00408ba45c33adac2a6f437f
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/team")
public class TeamController {

    @Autowired
    private TeamService teamService;

    @PostMapping("/apply")
    public ResponseEntity<Map<String, Object>> applyToTeam(
            @RequestHeader("X-User-ID") Integer userId,
            @RequestBody TeamApplyDTO applyDTO) {
        boolean success = teamService.applyToTeam(userId, applyDTO);
        Map<String, Object> response = new HashMap<>();
        response.put("success", success);
        return ResponseEntity.ok(response);
    }

    @GetMapping("/{postId}/detail")
    public ResponseEntity<TeamDetailDTO> getTeamDetail(
            @PathVariable Long postId,
            @RequestHeader("X-User-ID") Integer userId) {
        TeamDetailDTO detail = teamService.getTeamDetail(postId, userId);
        return detail != null ? ResponseEntity.ok(detail) : ResponseEntity.notFound().build();
    }

    @GetMapping("/{postId}/members")
    public ResponseEntity<List<TeamMember>> getTeamMembers(@PathVariable Long postId) {
        return ResponseEntity.ok(teamService.getTeamMembers(postId));
    }

    @GetMapping("/check-like")
    public ResponseEntity<Map<String, Boolean>> checkLikeStatus(
            @RequestParam Long postId,
            @RequestHeader("X-User-ID") Integer userId) {
        boolean isLiked = teamService.checkLikeStatus(userId, postId);
        Map<String, Boolean> response = new HashMap<>();
        response.put("isLiked", isLiked);
        return ResponseEntity.ok(response);
    }
}